package com.polaris.live.adapter.recharge

import android.widget.ImageView
import com.bumptech.glide.Glide
import com.polaris.live.R
import com.polaris.live.resp.back_resp.BannerBean
import com.polaris.live.utils.image.ImageUtils
import com.polaris.live.utils.image.normal
import com.polaris.live.utils.route.RouterUtils
import com.zhpan.bannerview.BaseBannerAdapter
import com.zhpan.bannerview.BaseViewHolder

/**
 * RechargeBannerAdapter
 * 充值banner
 *
 * @author Created by 长空 on 2023/10/23/020 10:23
 */
class RechargeBannerAdapter : BaseBannerAdapter<BannerBean>() {

    override fun bindData(
        holder: BaseViewHolder<BannerBean>,
        data: BannerBean,
        position: Int,
        pageSize: Int,
    ) {
        val imageView = holder.findViewById<ImageView>(R.id.item_banner)
        Glide.with(imageView.context)
            .load(ImageUtils.imgPath(data.pic))
            .normal()
            .into(holder.findViewById(R.id.item_banner))

        imageView.setOnClickListener {
            data.link?.ifEmpty {
                data.nativeLink?.ifEmpty { null }
            }?.let {
                RouterUtils.routerGoto(it)
            }
        }

    }

    override fun getLayoutId(viewType: Int): Int {
        return R.layout.adapter_recharge_banner
    }

}